package com.qk.management.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qk.common.Result;
import com.qk.dto.customer.CustomerDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 *  @author SHCJ
 *  @created 2025/10/16 18:15
 *  @description
 */
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
//    列表查询
    @GetMapping
    public Result selectByPage(CustomerDTO dto){
        return Result.success(customerService.selectByPage(dto));
    }
//    添加
    @PostMapping
    public Result add(@RequestBody Customer customer){
        customerService.save( customer);
        return Result.success();
    }

//    根据id查询
    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id) {
        return Result.success(customerService.getById( id));
    }
//    修改
    @PutMapping
    public Result update(@RequestBody Customer customer){
        customerService.updateById(customer);
        return Result.success();
    }
}
